package com.disapand.dingdang.model

import org.ktorm.database.Database
import org.ktorm.entity.Entity
import org.ktorm.entity.sequenceOf
import org.ktorm.schema.Table
import org.ktorm.schema.datetime
import org.ktorm.schema.int
import org.ktorm.schema.varchar
import java.time.LocalDateTime


/**
 * 系统可请求资源对象
 * @author disapand
 * @date 2022/2/26 - 19:08 星期六
 */
interface Resource : Entity<Resource> {
    companion object: Entity.Factory<Resource>()

    val id: Int
    var group: String
    var groupName: String
    var method: String
    var resource: String
    var resourceName: String
    var createdAt: LocalDateTime
}

/**
 * 资源表
 */
object Resources : Table<Resource>("d_resources") {
    val id = int("id").primaryKey().bindTo { it.id }
    val group = varchar("group").bindTo { it.group }
    val groupName = varchar("group_name").bindTo { it.groupName }
    val method = varchar("method").bindTo { it.method }
    val resourceName = varchar("resource_name").bindTo { it.resourceName }
    val resource = varchar("resource").bindTo { it.resource }
    val createdAt = datetime("created_at").bindTo { it.createdAt }
}

val Database.resources get() = this.sequenceOf(Resources)